package com.woniuxy.carlife.controller;


import com.alibaba.fastjson.JSON;
import com.woniuxy.carlife.Param.StoreUserParam;
import com.woniuxy.carlife.carlifecommonsweb.responsetemplate.Result;
import com.woniuxy.carlife.carlifecommonsweb.responsetemplate.StatusCode;
import com.woniuxy.carlife.domain.Tags;
import com.woniuxy.carlife.service.TagsService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName: TagsController
 *@Description: 门店服务标签前端控制器
 * @author: yanzhongliang     
 * @date: 2021-04-05
 */

@RestController
@Slf4j
@Api(tags = "门店服务标签接口信息")//用于描述接口类的相关信息，作用于类上
public class TagsController {
    @Resource
    private TagsService tagsService;

    @Resource
    private RedisTemplate redisTemplate;
    /**
     * 功能描述〈根据门店id查询门店服务标签在前端提供展示〉
     * @author: yanzhongliang
     * @param: storeId
     * @return: StoreTagsDto
     * @Date 2021/4/7 17:10
     * @throws
     */

    //@ApiOperation用于描述接口方法，作用于方法上
    @ApiOperation(value = "根据门店id查询门店服务标签在前端提供展示",notes = "<span style='color:red;'>用来根据门店id查询门店服务标签在前端提供展示的接口</span>")
    //@ApiResponses用于描述响应状态信息
    @ApiResponses({
            @ApiResponse(code = 40012,message = "查询成功",response = StoreUserParam.class),
            @ApiResponse(code=70022,message = "门店名不存在，查询为空"),
            @ApiResponse(code=70021,message = "门店id为空")
    })
    //@ApiImplicitParams用于描述接口参数
    @ApiImplicitParams({
            //dataType:参数类型
            //paramType:参数由哪里获取     path->从路径中获取，query->?传参，body->ajax请求
            @ApiImplicitParam(name = "storeId",value = "门店ID",dataType = "int",paramType = "query",example = "1")
    })

    @GetMapping("/ordinary/tagsfindList")
    public Result getTagsFindList( @ApiParam("传入门店ID") Integer storeId){
        log.info("getTagsFindList开始：参数：{}",storeId);
        //判断门店id是否为空
        if (storeId!=null){
            //根据门店ID查询门店服务标签
            List<Tags>tagsList= tagsService.getTagsFindList(storeId);
            log.info("getTagsFindList结束查询到门店服务标签集合：参数：{}",tagsList);
            //判断查询到的门店服务标签是否为空
            if (!tagsList.isEmpty()){
                //将查询到的门店详情转成json字符串
                String strJson= JSON.toJSONString(tagsList);
                // 存入redis
                redisTemplate.opsForHash().put("store","storeTagsName",strJson);

                return new Result(true, StatusCode.SEARCH_SUCCESSFUL,"查询门店服务标签成功",tagsList);
            }else {
                return new Result(false, StatusCode.STORENAME_EMPTY,"查询结果有误，门店不存在");
            }

        }else {
            return new Result(false, StatusCode.ID_EMPTY,"门店ID为空");
        }



    }

}

